module AutoBase
  class ActionWord
    class Instance
      include Actionable

      def initialize(action_word)
        @action_word = action_word
      end

      def added(session, param = {})
        text = session.cmd added_attr('@command')
        matches = added_attr("@match")
        AutoBase::Message.new(text, matches)
      end

      def deleted(session, param = {})
        text = session.cmd deleted_attr('@command')
        matches = deleted_attr("@match")
        AutoBase::Message.new(text, matches)
      end

      private
      def added_attr(name)
        @action_word.instance_variable_get(name)
      end

      def deleted_attr(name)
        attr = @action_word.instance_variable_get('@deleted')
        unless attr
          AutoBase.error "not deleted action_word"
          return
        end
        attr.instance_variable_get(name)
      end
    end
  end
end